home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / mm / putc.c < prev    next >
C/C++ Source or Header  |  1990-07-15  |  1KB  |  47 lines

  1. /* MM must occasionally print some message.  It uses the standard library
  2.  * routine prink().  (The name "printf" is really a macro defined as "printk").
  3.  * Printing is done by calling the TTY task directly, not going through FS.
  4.  */
  5.  
  6. #include "mm.h"
  7. #include <minix/com.h>
  8.  
  9. #define STD_OUTPUT          1    /* file descriptor for standard output */
  10. #define BUF_SIZE          100    /* print buffer size */
  11.  
  12. PRIVATE int buf_count;        /* # characters in the buffer */
  13. PRIVATE char print_buf[BUF_SIZE];    /* output is buffered here */
  14. PRIVATE message putch_msg;    /* used for message to TTY task */
  15.  
  16. FORWARD void F_l_u_s_h();
  17.  
  18. /*===========================================================================*
  19.  *                putc                         *
  20.  *===========================================================================*/
  21. PUBLIC void putc(c)
  22. char c;
  23. {
  24.  
  25.   /* Accumulate another character.  If '\n' or buffer full, print it. */
  26.   print_buf[buf_count++] = c;
  27.   if (c == '\n' || buf_count == BUF_SIZE) F_l_u_s_h();
  28. }
  29.  
  30.  
  31. /*===========================================================================*
  32.  *                F_l_u_s_h                     *
  33.  *===========================================================================*/
  34. PRIVATE void F_l_u_s_h()
  35. {
  36. /* Flush the print buffer by calling TTY task. */
  37.  
  38.   if (buf_count == 0) return;
  39.   putch_msg.m_type = TTY_WRITE;
  40.   putch_msg.PROC_NR  = 0;
  41.   putch_msg.TTY_LINE = 0;
  42.   putch_msg.ADDRESS  = print_buf;
  43.   putch_msg.COUNT = buf_count;
  44.   sendrec(TTY, &putch_msg);
  45.   buf_count = 0;
  46. }
  47.